

;Const & Variables
;===================================

Constants: left, right, boat, cat, rat, grain, farmer
variables: x,y,z

Constants: 
a - cat, 
b - rat, 
c - grain, 
d - farmer, 
e - boat, 

S = side
E = empty


;Predicates:
;======================================
side (x,y)              ; x is on side y
eat (x,y)               ; x will eat y (if unsupervised)
load (x)                ; x is loaded into the boat
unload (x,y)    ; x is unloaded onto location y
moveboat (x)    ; move boat to the x side
inboat (x)              ; x is in the boat
capacity (x)    ; x it at capacity
empty (x)               ; x is empty
supervised(x,y) ; x and y are supervised
isgoal                  ; Goal has been reached


;Axioms
;=========================================

;MoveBoat
  (NOT (side (boat, y))) AND inboat (farmer) IMPLIES moveboat (y) 
  moveboat (y) IMPLIES side (boat,y)

;Unload
  (NOT empty(boat)) AND (side (boat,y) IMPLIES (unload (x,y))
  unload (x,y) AND side(boat,y) AND inboat (x) IMPLIES side (x,y) AND (NOT inboat(x))     

;Load
  (side(boat,y)) AND side(x, y) AND (not (capacity (boat))) IMPLIES (load (x))
  load (x)) IMPLIES (NOT side (x,y) AND inboat (x))

;Aux
        load (x) AND load (y) AND load (farmer) IMPLIES capacity (boat)
        supervised(x,y) IMPLIES NOT (eat(x,y))
        empty(boat) IMPLIES (NOT (inboat (x))) AND (NOT (inboat (y))) AND (NOT (inboat (z)))
        ( and (side(farmer, right)) (side(cat, left)) (side(rat, left)) ) IMPLIES (eat (cat, rat))
        ( and (side(farmer, left)) (side(cat, right)) (side(rat, right)) ) IMPLIES (eat (cat, rat))
        ( and (side(farmer, right)) (side(rat, left)) (side(grain, left)) ) IMPLIES (eat (rat, grain))
        ( and (side(farmer, left)) (side(rat, right)) (side(grain, right)) ) IMPLIES (eat (rat, grain))
        (and (side(cat,right)) (side(rat,right)) (side(grain,right)) (side(farmer,right)) (side(boat,right))) IMPLIES isgoal
        (NOT (side (boat, left))) IMPLIES (side (boat, right))
        (NOT (side (boat, right))) IMPLIES (side (boat, left))

;======================================

(setf operators   
  '(
    ;ACTION
        ((moveboat X)   ; move boat to x side
    ;PRECOND
    ((side boat (NOT X)) (inboat farmer))
    ;ADD
    ((side boat X))
    ;DELETE
    ((side boat (NOT X))))
    
    ;ACTION
        ((unload X Y)           ; unload x item on y side
    ;PRECOND
    ((side boat Y) (inboat X) (not (empty boat)))
    ;ADD
    ((side X Y))
    ;DELETE
    ((inboat X)))

    ;ACTION
        ((load X Y)             ; unload x item from y side
    ;PRECOND
    ((side boat Y) (side X Y) (NOT (capacity boat)))
    ;ADD
    ((inboat X))
    ;DELETE
    ((side X Y)))
))




;=======================================

;Initial State:
(setf start-state
  '((side cat left)
    (side rat left)
    (side grain left)
    (side farmer left)
    (side boat left)
    (empty(boat))))

;Goal
(setf goal-state
  '((side cat right)
    (side rat right)
    (side grain right)
    (side farmer right)
    (side boat right)
    (empty(boat))))



;Plan
;=======================================

load (rat)
load (farmer)

moveboat (right)

unload (farmer)
unload (rat)
load (farmer)

moveboat (left)
unload (farmer)
load (grain)
load (farmer)

moveboat (right)
unload (farmer)
unload (grain)
load (rat)
load (farmer)

moveboat (left)
load (cat)

moveboat (right)
unload (cat)
unload (farmer)
unload (rat)









